<?php
class AssetActController  extends Zone_Action{
	public function indexAction(){
		
	}

	public function deleteAction(){
		$ids = $_POST["ID"];
		$user_id = get_user_id();
		if(empty($ids)==true){
			return $this->setJSON(array(
				alert => error("Chưa tài sản nào được chọn.")
			));
		}
		if(is_array($ids)==true){
			$stringID = join(",",$ids);
			$this->Model->delete("assets","`ID` in ($stringID) AND `created_by_id`='$user_id'");
			return $this->setJSON(array(
				redirect => "#Asset/"
			));
		}
	}
	public function changestatusAction(){
		$ids = $_POST["ID"];
		$user_id = get_user_id();
		if(empty($ids)==true){
			return $this->setJSON(array(
				alert => error("Chưa tài sản nào được chọn.")
			));
		}
		if(is_array($ids)==true){
			foreach($ids as $kid=>$vid){
				$ar = $this->Model->fetchRow("SELECT * FROM `assets` WHERE `ID`='$vid'");
				if($ar['status']=='using'){
					$arr = array("status"=>"dont");
				}else{
					$arr = array("status"=>"using");
				}
				$this->Model->update("assets",$arr,"`ID`='$vid'");
			}
			return $this->setJSON(array(
				redirect => "#Asset/"
			));
		}
	}
}	